package com.elinkway.infinitemovies.async;

import android.content.Context;

import com.elinkway.infinitemovies.bean.UpdatestreamBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.UpdatestreamBeanParser;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by wangyemin on 2015/12/14.
 */
public class UpdatestreamTask extends MoviesHttpAsyncTask<UpdatestreamBean> {
    private String eid;
    private int state;
    private String url;
    private RequestResultListener<UpdatestreamBean> listener;

    public UpdatestreamTask(Context context, String url) {
        super(context);
        this.url = url;
    }

    public void setEid(String eid) {
        this.eid = eid;
    }

    public void setState(int state) {
        this.state = state;
    }

    public void setListener(RequestResultListener<UpdatestreamBean> listener) {
        this.listener = listener;
    }

    @Override
    public LVideoDataHull<UpdatestreamBean> doInBackground() {
        return MoviesHttpApi.updateStreamRequest(new UpdatestreamBeanParser(), url, eid, state);
    }

    @Override
    public void onPostExecute(int updateId, UpdatestreamBean result) {
        if (null != listener)
            listener.onRequestSuccess(updateId, result);
    }

    @Override
    public boolean onPreExecute() {
        return super.onPreExecute();
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        if (null != listener)
            listener.onRequestFailed();
        super.netErr(updateId, errMsg);
    }

    @Override
    public void netNull() {
        super.netNull();
        if (null != listener)
            listener.onRequestFailed();
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
        if (null != listener)
            listener.onRequestFailed();
    }
}
